﻿/// <reference path="jquery-1.4.4.js" />

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// EditFormType

/*
Giá trị của form là : EditFormType.Create(default) Or EditFormType.Modify Or EditFormType.View Or EditFormType.None
*/
var FormType = 0;

/*
Enum kieu form là : Create , Modify , View , None
*/
var EditFormType = {
    "Create": 0,
    "Modify": 1,
    "View": 2,
    "None": 3
}
Object.freeze(EditFormType);


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// VnrUtils

/*
This is Javascript Utility Class using for common manipulate 

Author : Tung.Ly
Modified Date : 2013Jul04
*/
var VnrUtils = new function () {
    //accessor variable    

    this.addDays = fnAddDays; //Add number of days into specify Date
    this.changeStringToDate = fnChangeStringToDate; //change string with pattern (dd/MM/yyyy) to Date.
    this.StringToDate = fnStringToDate; //Convert string to Date with pattern (MM/dd/yyyy)
    this.getInputValue = fnGetInputValue; //get get Input Value by Id
    this.isInputChecked = fnIsInputChecked; //Lấy giá trị checked của raidiobutton hoặc checkbox
    this.getInputId = fnGetInputId; //Get id (complete) of input tag
    this.setInputValue = fnSetInputValue; //set Input value by id
    this.isNotNullOrEmpty = fnIsNotNullOrEmpty; //Check value is Not Null or Empty    
    this.isNumber = fnIsNumber; //Check value input is Number type or not
    this.isString = fnIsString; //Check value input is String type or not
    this.trim = fnTrim; //Removes the leading and trailing white space and line terminator characters from a string
    this.stringToJson = fnStringToJson; //Convert String to Json format
    this.getHourMinute = fnToHourMinute; //get HourMinute with pattern (HH:mm)
    this.alert = fnAlert; //Display alert Dialog Box
    this.notify = fnNotify; // display notify
    this.confirm = fnConfirm; //Display Confirmation Dialog Box
    this.convertToString = fnConvertToString; // Convert different objects to string
    this.isJsonFormat = fnIsJsonFormat; //check string is Json format
    this.getMonth = fnGetMonth; //Get string Month (01->12)
    this.getDate = fnGetDate; //Get string Date (01->31)
    this.getYear = fnGetYear; //Get string Year
    this.navigate = fnNavigate; //Navigate to specify link
    this.navigateNewTab = fnNavigateNewTab; //Navigate to specify link to other tab    
    this.hasInputId = fnHasInputId; //Check InputId is exists or not
    this.show = fnShowElement; //Show element by Id
    this.hide = fnHideElement; //Hide element by Id
    this.print = fnPrintText; //Print to screen the text message
    this.splitFullName = fnSplitFullName; //Split FullName into FirstName , LastName
    this.setAttribute = fnSetAttribute; //Set attribute for element by inputId
    this.formatNumber = fnFormatNumber; //Format number with pattern (x,xxx,xxx.00)
    this.setTimeOut = fnSetTimeOut; //Gọi 1 function sau 1 thời gian (tính bằng mili giây)
    this.getSelectedValue = getSelectedValue; //Lấy value của dropdownlist đã chọn
    this.getSelectedText = getSelectedText; //Lấy text của dropdownlist đã chọn
    this.checkTypeOf = fnCheckTypeOf; //kiểm tra biến có thuộc 1 kiểu dữ liệu hay không 
    this.ajax = fnAjax;
    this.stringToInt = fnParseInt;
    this.stringToFloat = fnParseFloat;
    this.log = fnLog;
    this.logClear = fnLogClear;


    function fnParseInt(strVariable) {
        /// <summary>Chuyển chuổi thành Int </summary>
        /// <param name="strVariable" type="String">Giá trị</param>                
        /// <returns type="Number"></returns>    
        var _variable = 0;
        try {
            _variable = parseInt(strVariable);
        } catch (e) {
            console.log(e.message);
        }
        return _variable;
    }

    function fnParseFloat(strVariable) {
        /// <summary>Chuyển chuổi thành Float </summary>
        /// <param name="strVariable" type="String">Giá trị</param>                
        /// <returns type="Float"></returns>  
        var _variable = 0;
        try {
            _variable = parseFloat(strVariable);
        } catch (e) {
            console.log(e.message);
        }
        return _variable;
    }

    function fnCheckTypeOf(variableName, dataType) {
        /// <summary>kiểm tra biến có thuộc 1 kiểu dữ liệu hay không </summary>
        /// <param name="variableName" type="String">variable Name</param>                
        /// <param name="dataType" type="String">Data Type</param>                
        /// <returns type="Boolean"></returns>    

        var _variableName = typeof (variableName);
        var _isEqual = false;
        if (_variableName == dataType.toLowerCase()) {
            _isEqual = true;
        }
        return _isEqual;
    }

    function getSelectedValue(selectId) {
        /// <summary>Lấy value của dropdownlist đã chọn</summary>
        /// <param name="selectId" type="String">Id của dropdownlist</param>                
        /// <returns type="String"></returns>    

        selectId = fnGetInputId(selectId, "select");
        var value1 = $("#" + selectId + " option:selected").val();
        return value1;
    }

    function getSelectedText(selectId) {
        /// <summary>Lấy text của dropdownlist đã chọn</summary>
        /// <param name="selectId" type="String">Id của dropdownlist</param>                          
        /// <returns type="String">/returns> 
        selectId = fnGetInputId(selectId, "select");
        var text = $("#" + selectId + " option:selected").text();
        return text;
    }

    function fnStringToDate(dt) {
        /// <summary>Convert string to Date with pattern (MM/dd/yyyy)</summary>
        /// <param name="dt" type="String">string date (ex:8/24/2009)</param>        
        /// <returns type="Date"></returns>
        var dt_date = new Date(dt);
        return dt_date;
    }


    function fnFormatNumber(num) {
        /// <summary>Format number with pattern (x,xxx,xxx.00)</summary>
        /// <param name="num" type="Number">Number want to format</param>        
        /// <returns type="String"></returns>
        num = isNaN(num) || num === '' || num === null ? 0.00 : num;
        return parseFloat(num).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,");
    }

    function fnSetAttribute(inputId, attName, attValue) {
        /// <summary>Set attribute for element by inputId</summary>
        /// <param name="inputId" type="String">Id of Input tag</param>        
        /// <param name="attName" type="String">name of attribute</param>        
        /// <param name="attValue" type="String">value of attribute want to set</param>        
        var obj = document.getElementById(inputId);
        if (!fnIsNullOrEmpty(obj)) {
            obj.setAttribute(attName, attValue);
        }

    };



    function fnSplitFullName(txtFullNameId, txtLastNameId, txtFirstNameId) {
        /// <summary>Split FullName into FirstName , LastName </summary>
        /// <param name="txtFullNameId" type="String">Id of Input FullName</param>        
        /// <param name="txtLastNameId" type="String">Id of Input  LastName</param>        
        /// <param name="txtFirstNameId" type="String">Id of Input FirstName</param>        


        var fullName = document.getElementById(txtFullNameId).value.trim();
        var col_array = fullName.split(" ");
        var part_num = 0;
        var lastName = "";
        var firstName = "";
        for (i = 0; i < col_array.length; i++) {
            if (i == col_array.length - 1)
                firstName = col_array[i];
            else
                lastName += col_array[i] + " ";
        }
        document.getElementById(txtFirstNameId).value = firstName;
        document.getElementById(txtLastNameId).value = lastName;
    }

    function fnPrintText(text) {
        /// <summary>Print to screen the text message</summary>
        /// <param name="text" type="String"></param>       

        return document.write(text);
    }

    function fnTrim(value) {
        /// <summary>Removes the leading and trailing white space and line terminator characters from a string</summary>
        /// <param name="value" type="String"></param>        
        /// <returns type="String"></returns>
        return value.trim();
    }

    function fnHasInputId(id) {
        /// <summary>Check InputId is exists or not</summary>
        /// <param name="id" type="String"></param>        
        /// <returns type="Boolean"></returns>
        var hasId = true;
        if (fnIsNullOrEmpty(document.getElementById(id))) {
            hasId = false;
        }
        return hasId;
    }

    function fnShowElement(divId) {
        /// <summary>Show element by Id</summary>
        /// <param name="divId" type="String"></param>        
        /// <returns type="Void"></returns>
        document.getElementById(divId).style.display = "block";
    }

    function fnHideElement(divId) {
        /// <summary>Hide element by Id</summary>
        /// <param name="divId" type="String"></param>        
        /// <returns type="Void"></returns>
        document.getElementById(divId).style.display = "none";
    }

    function fnNavigate(link) {
        /// <summary>Navigate to specify link</summary>
        /// <param name="link" type="String"></param>        
        document.location.href = link;
    }

    function fnNavigateNewTab(link) {
        /// <summary>Navigate to specify link to other tab</summary>
        /// <param name="link" type="String"></param>        

        var win = window.open(link, '_blank');
        win.focus();
    }

    function fnGetYear(date) {
        /// <summary>Get string Year </summary>
        /// <param name="date" type="Date"></param>        
        /// <returns type="String"></returns>
        return fnConvertToString(date.getFullYear());
    }

    function fnGetDate(date) {
        /// <summary>Get string Date (01->31).</summary>
        /// <param name="date" type="Date"></param>        
        /// <returns type="String"></returns>

        var dayNew = date.getDate() > 9 ? "" + date.getDate() : "0" + date.getDate();
        return dayNew;
    }

    function fnGetMonth(date) {
        /// <summary>Get string Month (01->12).</summary>
        /// <param name="date" type="Date"></param>        
        /// <returns type="String"></returns>

        var month = date.getMonth() + 1;

        var monthNew = month > 9 ? "" + month : "0" + month;
        return monthNew;
    }

    function fnIsJsonFormat(jsonString) {
        /// <summary>check string is Json format</summary>
        /// <param name="jsonString" type="String">The string of Json</param>                
        /// <returns type="Boolean"></returns>
        try {
            var val = eval('(' + jsonString + ')');
            return true;
        } catch (e) {
            console.log(e.message);
            return false;
        }
    }

    function fnConvertToString(objectValue) {
        /// <summary> Convert different objects to string.</summary>
        /// <param name="objectValue" type="Object">object Type as :Boolean , Date, Number ,String,Array</param>        
        /// <returns type="String"></returns>
        return String(objectValue);
    }

    function fnAddDays(currentDate, numberOfDays) {
        /// <summary> Add number of days into specify Date  .</summary>
        /// <param name="currentDate" type="Date"></param>
        /// <param name="numberOfDays" type="String"></param>
        /// <returns type="Date">return a new date was added amount of days</returns>

        try {
            if (!fnIsNumber(numberOfDays) || fnIsNullOrEmpty(numberOfDays)) {
                numberOfDays = 0;
            }

            currentDate.setDate(currentDate.getDate() + eval(numberOfDays));
            return currentDate;
        } catch (e) {
            console.log(e.message);
            alert("function addDays :" + e);
        }
        return new Date(1900, 0);
    }

    function fnChangeStringToDate(strDate) {
        /// <summary> change string with pattern (dd/MM/yyyy) to Date.</summary>
        /// <param name="strDate" type="String"></param>        
        /// <returns type="Date">return a date</returns>

        var arrDate = strDate.split("/");

        if (arrDate.length == 3) {
            //lay ngay , thang , nam
            var day = eval(arrDate[0]);
            var month = eval(arrDate[1]);
            var year = eval(arrDate[2]);

            //lấy ngày
            var dateNew = new Date(year, month - 1, day);
            return dateNew;
        }
        else {
            return new Date(1900, 1, 1);
        }


    }

    function fnToHourMinute(date) {
        /// <summary> get HourMinute with pattern (HH:mm)</summary>
        /// <param name="date" type="Date">input the date </param>        
        /// <returns type="String">return HourMinute</returns>

        var hourMinute = "";
        var hour = 0;
        var minute = 0;

        if (date instanceof Date) {
            hour = date.getHours();
            minute = date.getMinutes();
            hour > 9 ? hourMinute = hour.toString() : hourMinute = "0" + hour.toString();
            hourMinute += ":";
            minute > 9 ? hourMinute += minute.toString() : hourMinute += "0" + minute.toString();
        }
        else {
            hourMinute = "00:00";
        }

        return hourMinute;
    }

    function fnGetInputId(id, tagName) {
        /// <signature>
        /// <summary> Get id (complete) of input tag.</summary>
        /// <param name="id" type="String">Id in html tag</param>        
        /// <returns type="String">return Id</returns>
        /// </signature>

        /// <signature>
        /// <summary> Get id (complete) by tag name .</summary>
        /// <param name="id" type="String">Id in html tag</param>        
        /// <param name="tagName" type="String">Get tag name in html tag</param>        
        /// <returns type="String">return Id</returns>
        /// </signature>
        var _tagName = 'input';
        try {
            if (!fnCheckTypeOf(tagName, DataType.Undefined)) {
                _tagName = tagName;
            }
            var inputs = document.getElementsByTagName(_tagName);
            for (var index = 0; index < inputs.length; ++index) {
                var inputId = inputs[index].getAttribute('id');
                if (inputId != null) {
                    var inputIdLower = inputId.toLowerCase();
                    if (inputIdLower.indexOf(id.toLowerCase()) > -1) {
                        return inputId;
                    }
                }
            }
        } catch (e) {
            console.log(e.message);
        }
        return "";
    }

    function fnGetInputValue(id) {
        /// <summary> get get Input Value by Id.</summary>
        /// <param name="id" type="String">Get Input Id in html tag</param>        
        /// <returns type="String">return IdValue</returns>


        if (fnIsNullOrEmpty(document.getElementById(id))) {
            return "";
        }

        var idValue = document.getElementById(id).value.trim();

        return idValue;
    }


    function fnSetInputValue(id, idValue) {
        /// <summary>set Input value by id.</summary>
        /// <param name="id" type="String">Get Input Id in html tag</param>        
        /// <param name="idValue" type="String">Input value of Id need set value</param>        
        /// <returns type="Boolean">return true if success // return false if failure</returns>

        if (fnIsNullOrEmpty(document.getElementById(id))) {
            return false;
        }
        document.getElementById(id).value = idValue.trim();
        return true;
    }

    function fnIsNullOrEmpty(value) {
        /// <summary>Check value is Null or Empty.</summary>
        /// <param name="value" type="String"></param>                
        /// <returns type="Boolean"></returns>

        var isNullorEmpty = false;
        switch (value) {
            case "": isNullorEmpty = true; break;
            case null: isNullorEmpty = true; break;
            case undefined: isNullorEmpty = true; break;
            default: isNullorEmpty = false;
        }
        return isNullorEmpty;
    }

    function fnIsNotNullOrEmpty(value) {
        /// <summary>Check value is Not Null or Empty.</summary>
        /// <param name="value" type="String"></param>                
        /// <returns type="Boolean"></returns>

        return !fnIsNullOrEmpty(value);
    }

    function fnStringToJson(jsonString) {
        /// <summary>Convert String to Json format</summary>
        /// <param name="jsonString" type="String">The string of Json</param>                
        /// <returns type="Json"></returns>
        try {
            var val = eval('(' + jsonString + ')');
            return val;
        } catch (e) {
            console.log(e.message);
            alert("function StringToJson : " + e);
        }


    }

    function fnIsNumber(value) {
        /// <summary>Check value input is Number type or not</summary>
        /// <param name="value" type="String">The value want to check</param>                
        /// <returns type="Boolean"></returns>

        var _isNumber = false;
        if (!isNaN(value)) {
            _isNumber = true;
        }
        return _isNumber;
    }

    function fnIsString(value) {
        /// <summary>Check value input is String type or not</summary>
        /// <param name="value" type="String">The value want to check</param>                
        /// <returns type="Boolean"></returns>

        return !fnIsNumber(value);
    }


    function fnAlert(alertMessage) {
        /// <summary>Display alert Dialog Box (Ext.Msg.alert)</summary>                
        /// <param name="alertMessage" type="String">The value want to alert</param>                
        try {
            Ext.Msg.alert('Error', alertMessage);
        } catch (e) {
            window.alert(alertMessage);
        }
    }

    function fnNotify(notifyMessage) {
        /// <summary>Display notify Dialog Box (Ext.Msg.notify)</summary>                
        /// <param name="notifyMessage" type="String">The message will notify</param>                
        Ext.Msg.notify('Thông Báo', notifyMessage);
    }


    function fnConfirm(confirmMessage) {
        /// <summary>Display Confirmation Dialog Box</summary>                
        /// <param name="confirmMessage" type="String">The value want to inform to user</param>                
        /// <returns type="Boolean"></returns>
        return window.confirm(confirmMessage);
    }

    function fnIsInputChecked(id) {
        /// <summary>Lấy giá trị checked của raidiobutton hoặc checkbox</summary>        
        /// <param name="id" type="String">Id của radiobutton hoặc checkbox</param>        
        /// <returns type="Boolean"></returns>
        var isChecked = false;
        if (fnIsNullOrEmpty(document.getElementById(id))) {
            return false;
        }
        isChecked = document.getElementById(id).checked;
        return isChecked;
    }

    function fnSetTimeOut(functionName, miliSeconds) {
        /// <summary>Gọi 1 function sau 1 thời gian (tính bằng mili giây)</summary>        
        /// <param name="functionName" type="String">Tên function</param>        
        /// <param name="miliSeconds" type="Number">số mili giây </param>        
        /// <returns type="Boolean"></returns>
        setTimeout(functionName, miliSeconds);
    }

    function fnLog(logValue) {
        /// <summary>Ghi log vào console </summary>        
        /// <param name="logValue" type="String">Tên function</param>        
        /// <returns type="Void"></returns>
        console.log(logValue);
    }

    function fnLogClear() {
        /// <summary>clear log trong console </summary>        
        /// <returns type="Void"></returns>
        console.clear();
    }


    function fnAjax(_method, _datatype, _data, _function, _async, _evalScript) {
        /// <signature>
        /// <summary>Gọi ajax</summary>        
        /// <param name="_method" type="String">VnrAjaxSetting.Method.Get or VnrAjaxSetting.Method.Post</param>        
        /// <param name="_datatype" type="String">VnrAjaxSetting.Datatype.</param>        
        /// <param name="_data" type="Object">{ 'mode': mode, 'code': numberId }</param>        
        /// <param name="_function" type="Function">
        /// function(response){
        ///     xử lý code khi response thành công
        ///  }
        ///</param>        
        /// <returns type="Void"></returns>
        /// </signature>

        /// <signature>
        /// <summary>Gọi ajax</summary>        
        /// <param name="_method" type="String">VnrAjaxSetting.Method.Get or VnrAjaxSetting.Method.Post</param>        
        /// <param name="_datatype" type="String">VnrAjaxSetting.Datatype.</param>        
        /// <param name="_data" type="Object">{ 'mode': mode, 'code': numberId }</param>        
        /// <param name="_function" type="Function">
        /// function(response){
        ///     xử lý code khi response thành công
        ///  }
        ///</param>        
        /// <param name="_async" type="Boolean">VnrAjaxSetting.Async.True or VnrAjaxSetting.Async.False </param>        
        /// <param name="_evalScript" type="Boolean">VnrAjaxSetting.EvalScript.True or VnrAjaxSetting.EvalScript.True </param>        
        /// <returns type="Void"></returns>
        /// </signature>

        var _asynchronize = false;
        var _evaluateScript = true;
        if (arguments.length > 4) {
            _asynchronize = _async;
            _evaluateScript = _evalScript;
        }

        var req = new Request({
            method: _method,
            async: _asynchronize,
            dataType: _datatype,
            evalScript: _evaluateScript,
            url: "../../BaseControls/Views/CalcAjax.aspx",
            data: _data,
            onComplete: _function
        }).send();
    }

    this.Map = new function () {

        var map = new Object(); // or var map = {};
        this.put = fnPut;
        this.get = fnGet;
        this.getObject = fngetObject;
        this.clear = fnClear;
        this.getLength = fnGetLength;

        function fnPut(key, value) {
            /// <summary>Set giá trị ứng với key</summary>        
            /// <param name="key" type="String">key của Map</param>        
            /// <param name="value" type="Object">giá trị ứng với key</param>        
            /// <returns type="Void"></returns>
            map[key] = value;
        }
        function fnGet(key) {
            /// <summary>lấy giá trị của Map ứng với key</summary>        
            /// <param name="key" type="String">key của map</param>        
            /// <returns type="Object"></returns>
            return map[key];
        }

        function fngetObject() {
            /// <summary>lấy toàn bộ giá trị của Map</summary>        
            /// <returns type="Object"></returns>
            return map;
        }

        function fnClear() {
            /// <summary>Xoá toàn bộ Map</summary>        
            /// <returns type="Void"></returns>
            map = new Object();
        }

        function fnGetLength() {
            /// <summary>length của Map</summary>        
            /// <returns type="Int"></returns>
            return Object.keys(map).length;
        }


    };
};
//end Utility class

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// VnrValidation

/*                      This is Javascript Validation Class using for validate

Author : Tung.Ly
Modified Date : 2013Jul07
*/

var VnrValidation = new function () {
    //variable
    var regIdentification = "^[0-9]{9}$";
    var regMaNv = "^[0-9]{5}$";

    //properties
    this.validate_CMND = fnValidateCMND;
    this.validate_MANV = fnValidateMANV;
    this.validate_MACHAMCONG = fnValidateMANV;

    //function

    function fnValidateCMND(value) {
        /// <summary>ràng buộc số chứng minh nhân dân (bắt buộc nhập 9 số)</summary>        
        /// <param name="value" type="String"></param>        
        /// <returns type="Boolean"></returns>
        return validate(regIdentification, value);
    }

    function fnValidateMANV(value) {
        /// <summary>ràng buộc mã nhân viên (bắt buộc nhập 5 số)</summary>        
        /// <param name="value" type="String"></param>        
        /// <returns type="Boolean"></returns>
        return validate(regMaNv, value);
    }

    function validate(regPattern, value) {
        /// <summary>(Private) Ràng buộc dữ liệu theo 1 mẫu định sẵn</summary>        
        /// <param name="regPattern" type="String">Pattern </param>        
        /// <param name="value" type="String"></param>        
        /// <returns type="Boolean"></returns>
        var regex = new RegExp(regPattern);
        return regex.test(value);
    }

}; // close Validation class



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// VnrConstants

/*      All Constants of javascript
 
Author : Tung.Ly
Modified Date : 2013Jul04
*/
var VnrConstants = new function () {
    /// <field name='GuidEmpty' type='String'>trả về guid rổng :"lấy guid empty :00000000-0000-0000-0000-000000000000"</field>
    /// <field name='PersonalInfo' type='String'>trả về chuổi "PersonalInfo"</field>

    this.PersonalInfo = "PersonalInfo";
    this.BasePath = '/';
    this.GuidEmpty = "00000000-0000-0000-0000-000000000000";
    this.StringEmpty = "";

};  // close VnrConstant
Object.freeze(VnrConstants);


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// String

/*     String utilities of javascript
 
Author : Tung.Ly
Modified Date : 2014Feb07
*/
var String = new function () {
    //accessor variable    

    this.format = fnFormat;
    this.isNullOrEmpty = fnIsNullOrEmpty;
    this.toArray = fnToArray;
    this.empty = '';

    // function

    function fnFormat() {
        /// <summary>String.format('Name : {0} ;Age : {1}',Nguyen Van A , 25 ==> Name :Nguyen Van A ; Age : 25</summary>

        var s = arguments[0];
        for (var i = 0; i < arguments.length - 1; i++) {
            var reg = new RegExp("\\{" + i + "\\}", "gm");
            s = s.replace(reg, arguments[i + 1]);
        }
        return s;
    }

    function fnIsNullOrEmpty(value) {
        /// <summary>Check value is Null or Empty.</summary>
        /// <param name="value" type="String"></param>                
        /// <returns type="Boolean"></returns>

        var isNullorEmpty = false;
        switch (value) {
            case "": isNullorEmpty = true; break;
            case null: isNullorEmpty = true; break;
            case undefined: isNullorEmpty = true; break;
            default: isNullorEmpty = false;
        }
        return isNullorEmpty;
    }

    function fnToArray(stringValue, seperator) {
        /// <summary>Convert string to Array specify with seperator</summary>
        /// <param name="stringValue" type="String">chuổi cần chuyển sang Array</param>  
        /// <param name="seperator" type="String">dấu phân cách (vd:,)</param>                
        /// <returns type="Array"></returns>
        var array = stringValue.split(seperator);
        return array;
    }

};     // close String
Object.freeze(String);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// DataType

/*    Data Type of javascript
 
Author : Tung.Ly
Modified Date : 2013Aug16
*/
var DataType = new function () {
    this.String = "string";
    this.Number = "number";
    this.Boolean = "boolean";
    this.Null = null;
    this.Undefined = "undefined";
    this.Object = "object";
    this.Array = "array";

    this.isString = function (variable) {
        return fnCheckTypeOf(variable, DataType.String);
    };
    this.isNumber = function (variable) {
        return fnCheckTypeOf(variable, DataType.Number);
    };
    this.isBoolean = function (variable) {
        return fnCheckTypeOf(variable, DataType.Boolean);
    };
    this.isNull = function (variable) {
        return fnCheckTypeOf(variable, DataType.Null);
    };
    this.isUndefined = function (variable) {
        return fnCheckTypeOf(variable, DataType.Undefined);
    };

}
Object.freeze(DataType);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// VnrAjaxSetting

/*  Cấu hình Ajax
 
Author : Tung.Ly
Modified Date : 2013Aug16
*/
var VnrAjaxSetting = new function () {
    this.Method = new function () {
        this.Get = "get";
        this.Post = "post";
    };
    this.AsyncType = new function () {
        this.Async = true;
        this.Sync = false;
    };
    this.DataType = new function () {
        // this.Ajax = "ajax";
        this.Json = "json";
    };

    this.RequestStatus = new function () {
        /// <summary>trạng thái request của onsuccess</summary>
        this.Success = "success";
        this.Notmodified = "notmodified";
        this.Error = "error";
        this.Timeout = "timeout";
        this.Parsererror = "parsererror";
    };

    //đóng băng lại các properties (không cho thay đổi data)
    Object.freeze(this.Method);
    Object.freeze(this.AsyncType);
    Object.freeze(this.DataType);
    Object.freeze(this.RequestStatus);

};   //clse VnrAjaxSetting
Object.freeze(VnrAjaxSetting);

var Ajax = new function () {
    this.submitAjax = fnSubmitAjax; // submit data in form to server
    this.getJson = fnGetJson; // get json data in order to get data or validation
    this.loadAjax = fnLoadAjax; //load user control vào div

    // function

    function fnSubmitAjax(_controller, _action, _formId, onSuccess) {
        ///<summary> submit data in form to server </summary>
        var _url = VnrConstants.BasePath + _controller + VnrConstants.BasePath + _action;
        var formData = $('form#' + _formId).serialize();

        $.ajax({
            url: _url,
            type: 'post',
            async: false,
            data: formData,
            success: function (result, status) {
                if (onSuccess != null) {
                    onSuccess(result);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("Status: " + textStatus); alert("Error: " + errorThrown);
            }
        });
    }

    function fnGetJson(_controller, _action, _jsonData, onSuccess) {
        ///<summary> get json data in order to get data or validation </summary>
        var _url = VnrConstants.BasePath + _controller + VnrConstants.BasePath + _action;
        $.ajax({
            url: _url,
            type: 'post',
            async: false,
            data: _jsonData,
            success: function (result, status) 
            {
                if (onSuccess != null) 
                {
                        onSuccess(result);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("Status: " + textStatus); alert("Error: " + errorThrown);
            }
        });
    }

    function fnLoadAjax(_controller, _action, _divId, _jsonData, onSuccess) {
        ///<summary> load user control vào div </summary>
        var _url = VnrConstants.BasePath + _controller + VnrConstants.BasePath + _action;
        $("#" + _divId).load(_url, _jsonData, function (data, status) {
            if (onSuccess != null) {
                if (status == VnrAjaxSetting.RequestStatus.Success) {
                    onSuccess(data, status);
                }
                else {
                    alert("return error");
                }
            }
        });
    }

};


///////////////////////////////////////////////////////////////////////////////////////////////
// Common 

Array.prototype.insertAfter = function (index, item) {
    this.splice(index, 0, item);
};